﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Escape
{
    class CubeModel
    {

        VertexBuffer vb;

        public CubeModel()
        {
            setUpVertecis();
        }

        public void Draw(Matrix m)
        {
            GameScreen.effect.World = m;
            //GameScreen.effect.AmbientLightColor = new Vector3(0.1f, 0.1f, 0.1f);

            GameScreen.effect.CurrentTechnique.Passes[0].Apply();

            Basic.device.SetVertexBuffer(vb);
            Basic.device.DrawPrimitives(PrimitiveType.TriangleList, 0, 8);
        }

        public void setUpVertecis()
        {

            List<VertexPositionNormalTexture> ver = new List<VertexPositionNormalTexture>();

            //front side
            ver.Add(new VertexPositionNormalTexture(new Vector3(0.0f, -1.0f, 1.0f), new Vector3(0, 0, 1), new Vector2(0.0f, 1.0f)));
            ver.Add(new VertexPositionNormalTexture(new Vector3(0.0f, 0.0f, 1.0f), new Vector3(0, 0, 1), new Vector2(0.0f, 0.0f)));
            ver.Add(new VertexPositionNormalTexture(new Vector3(1.0f, -1.0f, 1.0f), new Vector3(0, 0, 1), new Vector2(1.0f, 1.0f)));

            ver.Add(new VertexPositionNormalTexture(new Vector3(1.0f, -1.0f, 1.0f), new Vector3(0, 0, 1), new Vector2(1.0f, 1.0f)));
            ver.Add(new VertexPositionNormalTexture(new Vector3(0.0f, 0.0f, 1.0f), new Vector3(0, 0, 1), new Vector2(0.0f, 0.0f)));
            ver.Add(new VertexPositionNormalTexture(new Vector3(1.0f, 0.0f, 1.0f), new Vector3(0, 0, 1), new Vector2(1.0f, 0.0f)));

            //right side
            ver.Add(new VertexPositionNormalTexture(new Vector3(1.0f, -1.0f, 1.0f), new Vector3(1, 0, 0), new Vector2(0.0f, 1.0f)));
            ver.Add(new VertexPositionNormalTexture(new Vector3(1.0f, 0.0f, 1.0f), new Vector3(1, 0, 0), new Vector2(0.0f, 0.0f)));
            ver.Add(new VertexPositionNormalTexture(new Vector3(1.0f, -1.0f, 0.0f), new Vector3(1, 0, 0), new Vector2(1.0f, 1.0f)));

            ver.Add(new VertexPositionNormalTexture(new Vector3(1.0f, -1.0f, 0.0f), new Vector3(1, 0, 0), new Vector2(1.0f, 1.0f)));
            ver.Add(new VertexPositionNormalTexture(new Vector3(1.0f, 0.0f, 1.0f), new Vector3(1, 0, 0), new Vector2(0.0f, 0.0f)));
            ver.Add(new VertexPositionNormalTexture(new Vector3(1.0f, 0.0f, 0.0f), new Vector3(1, 0, 0), new Vector2(1.0f, 0.0f)));

            //left side

            ver.Add(new VertexPositionNormalTexture(new Vector3(0.0f, 0.0f, 1.0f), new Vector3(-1, 0, 0), new Vector2(1.0f, 0.0f)));
            ver.Add(new VertexPositionNormalTexture(new Vector3(0.0f, -1.0f, 1.0f), new Vector3(-1, 0, 0), new Vector2(1.0f, 1.0f)));
            ver.Add(new VertexPositionNormalTexture(new Vector3(0.0f, -1.0f, 0.0f), new Vector3(-1, 0, 0), new Vector2(0.0f, 1.0f)));

            ver.Add(new VertexPositionNormalTexture(new Vector3(0.0f, -1.0f, 0.0f), new Vector3(-1, 0, 0), new Vector2(0.0f, 1.0f)));
            ver.Add(new VertexPositionNormalTexture(new Vector3(0.0f, 0.0f, 0.0f), new Vector3(-1, 0, 0), new Vector2(0.0f, 0.0f)));
            ver.Add(new VertexPositionNormalTexture(new Vector3(0.0f, 0.0f, 1.0f), new Vector3(-1, 0, 0), new Vector2(1.0f, 0.0f)));

            // back side

            ver.Add(new VertexPositionNormalTexture(new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0, 0, -1), new Vector2(1.0f, 0.0f)));
            ver.Add(new VertexPositionNormalTexture(new Vector3(0.0f, -1.0f, 0.0f), new Vector3(0, 0, -1), new Vector2(1.0f, 1.0f)));
            ver.Add(new VertexPositionNormalTexture(new Vector3(1.0f, -1.0f, 0.0f), new Vector3(0, 0, -1), new Vector2(0.0f, 1.0f)));

            ver.Add(new VertexPositionNormalTexture(new Vector3(1.0f, -1.0f, 0.0f), new Vector3(0, 0, -1), new Vector2(0.0f, 1.0f)));
            ver.Add(new VertexPositionNormalTexture(new Vector3(1.0f, 0.0f, 0.0f), new Vector3(0, 0, -1), new Vector2(0.0f, 0.0f)));
            ver.Add(new VertexPositionNormalTexture(new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0, 0, -1), new Vector2(1.0f, 0.0f)));



            vb = new VertexBuffer(Basic.device, typeof(VertexPositionNormalTexture), ver.Count, BufferUsage.WriteOnly);
            vb.SetData(ver.ToArray());
        }
    }
}
